package com.asymptote.mid;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.Extent;
import javax.jdo.PersistenceManager;

import com.asymptote.DataUtil;
import com.asymptote.MidObject;
import com.asymptote.data.MemberEntity;
import com.google.appengine.api.datastore.Key;

public class Member extends MidObject {
	private static final long serialVersionUID = -2523949363688647026L;

	public Member() {
		setEntity( new MemberEntity() );
	}
	public Member(MemberEntity ce) {
		super(ce);
	}
	public Member save() {
		PersistenceManager pm = DataUtil.getPersistenceManager();
		MemberEntity result = null;
        try {
        	MemberEntity me = (MemberEntity)this.getEntity();
        	me.setEditTime();
            result = pm.makePersistent( me );
        } finally {
            pm.close();
        }
        return new Member( result );
	}

	public static Member getMemberByKey(Key key) {
		PersistenceManager pm = DataUtil.getPersistenceManager();
		MemberEntity be = null;
		try {
			be = pm.getObjectById( MemberEntity.class, key );
			be = pm.detachCopy( be );
		} finally {
			pm.close();
		}
		return new Member( be );
	}

	public static List<Member> getAll() {
		PersistenceManager pm = DataUtil.getPersistenceManager();
		List<Member> result = new ArrayList<Member>(0);
	    try {    	
	        Extent<MemberEntity> des = pm.getExtent(MemberEntity.class);
	        for( MemberEntity d : des ) {
	        	result.add( new Member(d));
	        }
		} finally {
	        pm.close();
	    }
	    return result;
	}
	//----------------------------------------------------------------
	public void setName(String name) {
		((MemberEntity)this.getEntity()).setName( name );
	}

	public String getName() {
		return ((MemberEntity)this.getEntity()).getName();
	}

	public void setPassword(String password) {
		((MemberEntity)this.getEntity()).setPassword( password );
	}

	public String getPassword() {
		return ((MemberEntity)this.getEntity()).getPassword();
	}

	public void setGender(boolean gender) {
		((MemberEntity)this.getEntity()).setGender( gender );
	}

	public boolean isGender() {
		return ((MemberEntity)this.getEntity()).isGender();
	}

	public void setIdNum(String idNum) {
		((MemberEntity)this.getEntity()).setIdNum( idNum );
	}

	public String getIdNum() {
		return ((MemberEntity)this.getEntity()).getIdNum();
	}

	public void setMobile(String mobile) {
		((MemberEntity)this.getEntity()).setMobile( mobile );
	}

	public String getMobile() {
		return ((MemberEntity)this.getEntity()).getMobile();
	}

	public void setEmail(String email) {
		((MemberEntity)this.getEntity()).setEmail( email );
	}

	public String getEmail() {
		return ((MemberEntity)this.getEntity()).getEmail();
	}

	public void setDesc(String desc) {
		((MemberEntity)this.getEntity()).setDesc( desc );
	}

	public String getDesc() {
		return ((MemberEntity)this.getEntity()).getDesc();
	}

	public void setPlace(Key place) {
		((MemberEntity)this.getEntity()).setPlace( place );
	}

	public Key getPlace() {
		return ((MemberEntity)this.getEntity()).getPlace();
	}
}
